﻿using B.S.BasicData.Api.Write.Applications.Commands.Accounts;
using B.S.BasicData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Api.Write.Controllers
{
    /// <summary>
    /// API控制器-写
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class ManagementController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        private readonly IMediator mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">中介者</param>
        public ManagementController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 删除 
        /// </summary>
        /// <param name="command">删除参数</param>
        /// <returns>返回任务</returns>
        [HttpPost("Delete")]
        public Task<ApiResult<object>> Delete([FromQuery]DeleteQueryCommand command) 
        {
            try
            {
                return mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 添加 
        /// </summary>
        /// <param name="command">添加参数</param>
        /// <returns>返回任务</returns>
        [HttpPost("Add")]
        public async Task<ApiResult<object>> Add(AddQueryCommand command)
        {
            try
            {
                return await mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }
        }



        /// <summary>
        /// 修改 
        /// </summary>
        /// <param name="command">修改参数</param>
        /// <returns>返回任务</returns>
        [HttpPost("Update")]
        public async Task<ApiResult<object>> Update(UpdateQueryCommand command)
        {
            try
            {
                return await mediator.Send(command);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
